package com.ruoyi.web.controller.crm;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BsArea;
import com.ruoyi.system.service.IBsAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地区设置Controller
 * 
 * @author ruoyi
 * @date 2020-11-05
 */
@RestController
@RequestMapping("/system/area")
public class BsAreaController extends BaseController
{
    @Autowired
    private IBsAreaService bsAreaService;

    /**
     * 查询地区设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(BsArea bsArea)
    {
        startPage();
        List<BsArea> list = bsAreaService.selectBsAreaList(bsArea);
        return getDataTable(list);
    }

    /**
     * 导出地区设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:export')")
    @Log(title = "地区设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BsArea bsArea)
    {
        List<BsArea> list = bsAreaService.selectBsAreaList(bsArea);
        ExcelUtil<BsArea> util = new ExcelUtil<BsArea>(BsArea.class);
        return util.exportExcel(list, "area");
    }

    /**
     * 获取地区设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return AjaxResult.success(bsAreaService.selectBsAreaById(areaId));
    }

    /**
     * 新增地区设置
     */
    @PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "地区设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BsArea bsArea)
    {
        return toAjax(bsAreaService.insertBsArea(bsArea));
    }

    /**
     * 修改地区设置
     */
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "地区设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BsArea bsArea)
    {
        return toAjax(bsAreaService.updateBsArea(bsArea));
    }

    /**
     * 删除地区设置
     */
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "地区设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Long[] areaIds)
    {
        return toAjax(bsAreaService.deleteBsAreaByIds(areaIds));
    }
}
